package com.baizhi.mall.service.impl;

import com.baizhi.mall.annotation.LogAnnotation;
import com.baizhi.mall.entity.mysql.Admin;
import com.baizhi.mall.mapper.AdminDao;
import com.baizhi.mall.service.AdminService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao ad;

    @Override
    @LogAnnotation(type = "select",content = "搜索所有用户")
    public PageInfo<Admin> selectByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Admin>list =ad.selectList(null);
        PageInfo<Admin> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void insert(Admin admin) {
        ad.insert(admin);
    }

    @Override
    public void delete(Integer id) {
        ad.deleteById(id);
    }

    @Override
    public void update(Admin admin) {
        ad.updateById(admin);
    }

    @Override
    public void updateStatus(Integer status, Integer id) {
        ad.updateStatus(status,id);
    }

    @Override
    @LogAnnotation(type = "select",content = "搜索单个用户")
    public Admin selectOne(String username) {
        QueryWrapper<Admin>wrapper=new QueryWrapper<>();
        wrapper.eq("username",username);//第一个参数是表里面的字段名不能写成实体类的属性名
        return ad.selectOne(wrapper);
    }
}
